public class FoxJumping {
	private static final int MOD = 10007;

	public int getCount(int Tx, int Ty, int Mx, int My, int R, int[] bad) {
		int[][] qx = createQ(Tx, Mx, R);
		int[][] qy = createQ(Ty, My, R);
		int maxK = Math.min(Tx, Ty) / 10;
		int[][] ways = new int[maxK + 1][R + 1];
		ways[0][0] = 1;
		for (int i = 0; i < R; i++) {
			for (int j = 0; j <= maxK; j++) {
				ways[j][i + 1] = ways[j][i];
				for (int b : bad) {
					if (j >= b / 10)
						ways[j][i + 1] = (ways[j][i + 1] + ways[j - b / 10][i]) % MOD;
				}
			}
		}
		int[][] c = new int[R + 1][R + 1];
		for (int i = 0; i <= R; i++) {
			c[i][0] = 1;
			for (int j = 1; j <= i; j++)
				c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % MOD;
		}
		int result = 0;
		for (int i = 0; i <= maxK; i++) {
			for (int j = 0; j <= R; j++) {
				if (ways[i][j] == 0)
					continue;
				int curResult = qx[R - j][Tx - i * 10] * qy[R - j][Ty - i * 10];
				curResult %= MOD;
				curResult *= c[R][j];
				curResult %= MOD;
				curResult *= ways[i][j];
				curResult %= MOD;
				if (j % 2 == 0)
					result += curResult;
				else
					result -= curResult;
				result %= MOD;
			}
		}
		return ((result % MOD) + MOD) % MOD;
	}

	private int[][] createQ(int Tx, int Mx, int R) {
		int[][] qx = new int[R + 1][Tx + 1];
		qx[0][0] = 1;
		for (int i = 0; i < R; i++) {
			int sum = 0;
			for (int j = 0; j <= Tx; j++) {
				sum += qx[i][j];
				sum %= MOD;
				qx[i + 1][j] = sum;
				if (j >= Mx) {
					sum -= qx[i][j - Mx];
					sum += MOD;
					sum %= MOD;
				}
			}
		}
		return qx;
	}


	// BEGIN CUT HERE
	public static void main(String[] args) {
		if (args.length == 0) {
			FoxJumpingHarness.run_test(-1);
		} else {
			for (int i=0; i<args.length; ++i)
				FoxJumpingHarness.run_test(Integer.valueOf(args[i]));
		}
	}
// END CUT HERE
}

// BEGIN CUT HERE
class FoxJumpingHarness {
	public static void run_test(int casenum) {
		if (casenum != -1) {
			if (runTestCase(casenum) == -1)
				System.err.println("Illegal input! Test case " + casenum + " does not exist.");
			return;
		}
		
		int correct = 0, total = 0;
		for (int i=0;; ++i) {
			int x = runTestCase(i);
			if (x == -1) {
				if (i >= 100) break;
				continue;
			}
			correct += x;
			++total;
		}
		
		if (total == 0) {
			System.err.println("No test cases run.");
		} else if (correct < total) {
			System.err.println("Some cases FAILED (passed " + correct + " of " + total + ").");
		} else {
			System.err.println("All " + total + " tests passed!");
		}
	}
	
	static boolean compareOutput(int expected, int result) { return expected == result; }
	static String formatResult(int res) {
		return String.format("%d", res);
	}
	
	static int verifyCase(int casenum, int expected, int received) { 
		System.err.print("Example " + casenum + "... ");
		if (compareOutput(expected, received)) {
			System.err.println("PASSED");
			return 1;
		} else {
			System.err.println("FAILED");
			System.err.println("    Expected: " + formatResult(expected)); 
			System.err.println("    Received: " + formatResult(received)); 
			return 0;
		}
	}

	static int runTestCase(int casenum) {
		switch(casenum) {
		case 0: {
			int Tx                    = 2;
			int Ty                    = 2;
			int Mx                    = 1;
			int My                    = 1;
			int R                     = 2;
			int[] bad                 = {};
			int expected__            = 1;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}
		case 1: {
			int Tx                    = 2;
			int Ty                    = 2;
			int Mx                    = 1;
			int My                    = 1;
			int R                     = 3;
			int[] bad                 = {};
			int expected__            = 6;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}
		case 2: {
			int Tx                    = 10;
			int Ty                    = 10;
			int Mx                    = 10;
			int My                    = 10;
			int R                     = 1;
			int[] bad                 = {};
			int expected__            = 1;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}
		case 3: {
			int Tx                    = 10;
			int Ty                    = 10;
			int Mx                    = 10;
			int My                    = 10;
			int R                     = 1;
			int[] bad                 = {10};
			int expected__            = 0;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}
		case 4: {
			int Tx                    = 11;
			int Ty                    = 11;
			int Mx                    = 11;
			int My                    = 11;
			int R                     = 2;
			int[] bad                 = {10};
			int expected__            = 140;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}
		case 5: {
			int Tx                    = 123;
			int Ty                    = 456;
			int Mx                    = 70;
			int My                    = 80;
			int R                     = 90;
			int[] bad                 = {30, 40, 20, 10, 50};
			int expected__            = 6723;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}

		// custom cases

/*      case 6: {
			int Tx                    = ;
			int Ty                    = ;
			int Mx                    = ;
			int My                    = ;
			int R                     = ;
			int[] bad                 = ;
			int expected__            = ;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}*/
/*      case 7: {
			int Tx                    = ;
			int Ty                    = ;
			int Mx                    = ;
			int My                    = ;
			int R                     = ;
			int[] bad                 = ;
			int expected__            = ;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}*/
/*      case 8: {
			int Tx                    = ;
			int Ty                    = ;
			int Mx                    = ;
			int My                    = ;
			int R                     = ;
			int[] bad                 = ;
			int expected__            = ;

			return verifyCase(casenum, expected__, new FoxJumping().getCount(Tx, Ty, Mx, My, R, bad));
		}*/
		default:
			return -1;
		}
	}
}

// END CUT HERE
